package com.gitee.cashzhang27.test.boot.graphql.webmvc;

import com.gitee.cashzhang27.test.boot.graphql.webmvc.component.CharacterRepository;
import com.gitee.cashzhang27.test.boot.graphql.webmvc.resolvers.Mutation;
import com.gitee.cashzhang27.test.boot.graphql.webmvc.resolvers.Query;
import graphql.kickstart.tools.SchemaParser;
import graphql.schema.GraphQLSchema;
import lombok.AllArgsConstructor;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/11/16 15:18
 */
@AllArgsConstructor
@SpringBootApplication
public class BootGraphqlWebmvcApplication {

  private CharacterRepository characterRepository;

  public static void main(String[] args) {
    SpringApplication app = new SpringApplication(BootGraphqlWebmvcApplication.class);
    app.setBannerMode(Banner.Mode.OFF);
    app.run(args);
  }

  @Bean
  public GraphQLSchema createSchema() {
    SchemaParser parser =
        SchemaParser.newParser()
            .file("swapi.graphqls")
            .resolvers(new Query(this.characterRepository), new Mutation())
            .build();
    return parser.makeExecutableSchema();
  }

  /*
  POST Method
    {
      human(id:"1000"){
        id
        name
        appearsIn
        homePlanet
        friends{
          id
          name
          appearsIn
        }
      }
    }
   */

}
